package com.yc.blog.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.reactive.result.view.Rendering;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import reactor.core.publisher.Mono;

@Controller
@RequestMapping("user")
public class UserAction {

    @RequestMapping("logout")
    Mono<Rendering> logout(ServerWebExchange exchange) {
        return exchange.getSession()
                .doOnNext(WebSession::invalidate)
                .flatMap(s->Mono.just(Rendering.redirectTo("/index.html").build()));
//        return ServerResponse.temporaryRedirect(URI.create("/index.html")).build();
    }

}
